package com.settlement.system.service.impl;

import com.settlement.system.mapper.TblBillResponsibleReasonMapper;
import com.settlement.system.mapper.TblResponsibleReasonDtlMapper;
import com.settlement.system.common.exception.ServiceException;
import com.settlement.system.model.entity.common.TblBillResponsibleReason;
import com.settlement.system.service.ITblBillResponsibleReasonService;
import org.springframework.stereotype.Service;
import com.settlement.system.mapper.BaseMapper;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import jakarta.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * 损失原因/责任方/单据状态对应表 服务实现类
 * @author xiaochuan
 * @since 2020-06-11
 */
@Service
public class TblBillResponsibleReasonServiceImpl extends BaseServiceImpl implements ITblBillResponsibleReasonService {

    @Resource
    private TblBillResponsibleReasonMapper tblBillResponsibleReasonMapper;

    @Resource
    private TblResponsibleReasonDtlMapper tblResponsibleReasonDtlMapper;

    @Override
    public BaseMapper init() {
        return tblBillResponsibleReasonMapper;
    }

    @Override
    public Integer getBillNo(String str) throws ServiceException {
        try {
            return tblBillResponsibleReasonMapper.getBillNo(str);
        } catch (Exception e) {
            throw new ServiceException(e);
        }
    }

    @Override
    public List<TblBillResponsibleReason> getResponsibleReason(Map<String, Object> params) throws ServiceException {
        try {
            return tblBillResponsibleReasonMapper.getResponsibleReason(params);
        } catch (Exception e) {
            throw  new ServiceException(e);
        }
    }

    @Override
    @Transactional(propagation = Propagation.REQUIRED, rollbackFor = ServiceException.class)
    public void deleteByLossReasonNo(TblBillResponsibleReason tblBillResponsibleReason) throws ServiceException {
        try {
             tblBillResponsibleReasonMapper.deleteById(tblBillResponsibleReason);
             tblResponsibleReasonDtlMapper.deleteBylossReasonNo(tblBillResponsibleReason.getLossReasonNo());
        } catch (Exception e) {
            throw  new ServiceException(e);
        }
    }

    @Override
    public List<TblBillResponsibleReason> selectMainAndDtlByParam(Map<String, Object> params) throws ServiceException {
        try {
            return tblBillResponsibleReasonMapper.selectMainAndDtlByParam(params);
        } catch (Exception e) {
            throw  new ServiceException(e);
        }
    }

    @Override
    public List<TblBillResponsibleReason> getResponsibleReasonByParam(Map<String, Object> params) throws ServiceException {
        return tblBillResponsibleReasonMapper.getResponsibleReasonByParam(params);
    }
}

